package com.aigou.admin.dao.impl;

import com.aigou.admin.utils.JDBCUtils;
import com.aigou.admin.dao.Shop_cart_productDao;
import com.aigou.admin.entity.Shop_cart_product;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: May
 * @Date: 2024/12/3 17:05
 * @Version: 1.0
 */

@Repository
public class Shop_cart_productDaoImpl implements Shop_cart_productDao {
    @Override
    public List<Shop_cart_product> selectAll() {
        return JDBCUtils.executeQuery(Shop_cart_product.class, "select * from s_shop_cart_product");
    }

    @Override
    public Shop_cart_product selectById(String id) {
        List<Shop_cart_product> sales = JDBCUtils.executeQuery(Shop_cart_product.class, "select * from s_shop_cart_product where id =? ",id);
        if (sales.isEmpty()) {
            return null;
        }
        return sales.get(0);
    }

    @Override
    public Boolean insert(Shop_cart_product shopCartProduct) {
        int rows = JDBCUtils.executeUpdate("insert into s_shop_cart_product(id,shop_cart_id,product_id,product_num) values(?,?,?,?)"
                , shopCartProduct.getId(),shopCartProduct.getShop_cart_id(),shopCartProduct.getProduct_id(),shopCartProduct.getProduct_num());
        return rows > 0;
    }

    @Override
    public Boolean update(Shop_cart_product shopCartProduct) {
        int rows = JDBCUtils.executeUpdate("update s_shop_cart_product set shop_cart_id=?,product_id =?,product_num=? where id = ?"
                , shopCartProduct.getShop_cart_id(),shopCartProduct.getProduct_id(),shopCartProduct.getProduct_num(),shopCartProduct.getId());
        return rows > 0;
    }

    @Override
    public Boolean delete(String id) {
        int rows = JDBCUtils.executeUpdate("delete from s_shop_cart_product where id = ?", id);
        return rows >0;
    }

    @Override
    public Integer selectUserCount() {
        return JDBCUtils.executeCount("select count(*) from s_shop_cart_product");
    }

    @Override
    public List<Shop_cart_product> selectUserLimit(int start, int rows) {
        return JDBCUtils.executeQuery(Shop_cart_product.class,"select * from s_shop_cart_product limit ?,?",start,rows);
    }
}
